package org.kele.k8s.sc2020.comsumer.controller;

import org.kele.k8s.sc2020.comsumer.rpc.ProviderRpc;
import org.kele.k8s.sc2020.vo.EmployeeDTO;
import org.kele.k8s.sc2020.vo.KeleResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/comsumer")
@RestController
public class ConsumerDemoController {

    @Resource
    ProviderRpc providerRpc;

    @Autowired
    DiscoveryClient discoveryClient;

    @GetMapping("/kele/info")
    public KeleResponse<String> getInfo() {
        return providerRpc.getKeleInfo();
    }

    @GetMapping("/service")
    public KeleResponse<List<String>> getServices() {
        return KeleResponse.okBean(discoveryClient.getServices());
    }

    @GetMapping("/emp/{uid}")
    public KeleResponse<EmployeeDTO> getEmp(@PathVariable Integer uid) {
        return providerRpc.getEmpById(uid);
    }

}
